﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Nuclex.Game.States;
using Nuclex.Input;
using Nuclex.UserInterface;
using Nuclex.UserInterface.Controls.Desktop;
using Nuclex.UserInterface.Controls;

namespace WarPigs
{
    class SPStartingGameState : DrawableGameState
    {
        private GraphicsDeviceManager graphics;
        private GraphicsDevice device;
        private ContentManager Content;
        private SpriteBatch spriteBatch;
        private GuiManager guiManager;
        private InputManager inputManager;
        private GameStateManager gameStateManager;
        private Screen mainScreen;
        private SpriteFont arial24sprite;

        //SP Selection Elements
        LabelControl title;

        //Mapsize Control
        LabelControl MapSizeLabel;
        ListControl MapSizeList;

        //Maptype Control
        LabelControl MapTypeLabel;
        ListControl MapTypeList;

        //Sealevel Control
        LabelControl SealevelLabel;
        ListControl SeaLevelList;

        //Coastline Control
        LabelControl CoastlineLabel;
        LabelControl NorthLabel;
        OptionControl NorthOption;
        LabelControl EastLabel;
        OptionControl EastOption;
        LabelControl WestLabel;
        OptionControl WestOption;
        LabelControl SouthLabel;
        OptionControl SouthOption;

        //Difficulty Controls
        
        //Opponent Counter

        //Buttons
        ButtonControl BackButton;
        ButtonControl PmcOptionsButton;
        ButtonControl StartGameButton;


        //PMC Dialog Control

        public SPStartingGameState(GraphicsDeviceManager passedGraphics, GraphicsDevice passedDevice, ContentManager passedContent, SpriteBatch passedBatch, GuiManager passedManager, InputManager passedInput, GameStateManager passedStateManager)
        {
            graphics = passedGraphics;
            device = passedDevice;
            Content = passedContent;
            spriteBatch = passedBatch;
            guiManager = passedManager;
            inputManager = passedInput;
            gameStateManager = passedStateManager;

            Viewport viewport = device.Viewport;
            mainScreen = new Screen(viewport.Width, viewport.Height);
            guiManager.Screen = mainScreen;

            // Each screen has a 'desktop' control. This invisible control by default
            // stretches across the whole screen (all controls are positioned using both
            // a percentual position/size and absolute position/size). We change this to
            // prevent GUI or HUD elements from appearing outside the title-safe area.
            mainScreen.Desktop.Bounds = new UniRectangle(
              new UniScalar(0.1f, 0.0f), new UniScalar(0.1f, 0.0f), // x and y
              new UniScalar(0.8f, 0.0f), new UniScalar(0.8f, 0.0f) // width and height
            );
            // control, which means it will become visible and interactive.
            //mainScreen.Desktop.Children.Add(new SinglePlayerDialog());
            
        }


        protected override void OnEntered()
        {
            device.Clear(Color.Black);
            createSetupControls(mainScreen);


            //Font loader
            arial24sprite = Content.Load<SpriteFont>(@"ArialFont");
            base.OnEntered();
        }

        protected override void OnLeaving()
        {
            base.OnLeaving();
        }

        protected override void OnPause()
        {
            base.OnPause();
        }

        protected override void OnResume()
        {
            base.OnResume();
        }

        public override void Draw(Microsoft.Xna.Framework.GameTime gameTime)
        {
            
        }

        public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {

        }

        private void createSetupControls(Screen mainScreen)
        {
            //SP Selection Elements
            title = new LabelControl("Setup : Single Player");
            title.Bounds = new UniRectangle(10.0f, 30.0f, 110.0f, 24.0f);
            mainScreen.Desktop.Children.Add(title);

            //Mapsize Control
            MapSizeLabel = new LabelControl("Map Size: ");
            MapSizeLabel.Bounds = new UniRectangle(10.0f, 40.0f, 110.0f, 24.0f);
            MapSizeList = new ListControl();
            MapSizeList.Items.Add("Small");
            MapSizeList.Items.Add("Medium");
            MapSizeList.Items.Add("Large");
            MapSizeList.SelectionMode = ListSelectionMode.Single;
            MapSizeList.SelectedItems.Add(3);

            //Maptype Control
            MapTypeLabel = new LabelControl("Map Type: ");
            MapTypeLabel.Bounds = new UniRectangle(10.0f, 40.0f, 110.0f, 24.0f);
            MapTypeList = new ListControl();
            MapTypeList.Items.Add("Small");
            MapTypeList.Items.Add("Medium");
            MapTypeList.Items.Add("Large");
            MapTypeList.SelectionMode = ListSelectionMode.Single;
            MapTypeList.SelectedItems.Add(3);

            //Sealevel Control
            SealevelLabel = new LabelControl("Sea Level: ");
            SeaLevelList = new ListControl();
            SeaLevelList.Items.Add("Small");
            SeaLevelList.Items.Add("Medium");
            SeaLevelList.Items.Add("Large");
            SeaLevelList.SelectionMode = ListSelectionMode.Single;
            SeaLevelList.SelectedItems.Add(3);

            //Coastline Control
            CoastlineLabel = new LabelControl("Coastlines: ");
            NorthLabel = new LabelControl("N");
            NorthOption = new OptionControl();
            EastLabel = new LabelControl("E");
            EastOption = new OptionControl();
            WestLabel = new LabelControl("W");
            WestOption = new OptionControl();
            SouthLabel = new LabelControl("S");
            SouthOption = new OptionControl();


            BackButton = new ButtonControl();
            PmcOptionsButton = new ButtonControl();
            StartGameButton = new ButtonControl();
        }
    }
}
